﻿@using WineStore.Extends;
@using PagedList.Mvc;
@using PagedList;
@model PagedList.IPagedList<WineStore.Models.Product>
@{
    Layout = null;
}
<!--Delete Product-->
<script type="text/javascript">
    $(document).ready(function () {
        $(".RemoveProduct").click(function () {
            if (confirm("Are you sure delete "+$(this).attr("data-name")+" ?")) {
                // Get the id from the link 
                var recordToDelete = $(this).attr("data-id");
                if (recordToDelete != '') {
                    clearUpdateMessage();
                    // Perform the ajax post 
                    $.post("/Product/DeleteProduct", { "id": recordToDelete },
            function (data) {
                // Successful requests get here 
                // Update the page elements 
                $('#row-' + data.Id).fadeOut('slow');
                $('#update-message').text(htmlDecode(data.Message));

            });
                }
            }
        });
    });

    // Goi thong bao
    function clearUpdateMessage() {
        //Reset update-message area
        $('#update-message').text('');
    }

    // Giai ma thong bao
    function htmlDecode(value) {
        if (value) {
            return $('<div />').html(value).text();
        }
        else {
            return '';
        }
    }
</script>
<table border="1px;">
    <tr>
        <th>
            Product Id
        </th>
        <th>
            Category Name
        </th>
        <th>
            Product Name
        </th>
        <th>
            @Html.ActionLink("Product Price", "ShowProduct", new { sortOrder = ViewBag.SortPriceParm, currentFilter = ViewBag.CurrentFilter }, new { @class = "showTip L1", style = "color:White; text-decoration:none" })
        </th>
        <th>
            Date Add
        </th>
        <th>
            Product Image
        </th>
        <th>
            Change
        </th>
    </tr>
    @foreach (var item in Model)
    {
        <tr id="row-@item.ProductId">
            <td>
                @Html.DisplayFor(product => item.ProductId)
            </td>
            <td>
                @Html.DisplayFor(product => item.Category.CategoryName)
            </td>
            <td>
                @Html.DisplayFor(product => item.ProductName)
            </td>
            <td>
                @Html.DisplayFor(product => item.ProductPrice)
            </td>
            <td>
                @Html.DisplayFor(product => item.DateAdd)
            </td>
            <td>
                <div class="image_shine">
                    @Html.ImageFor(product => "../../Content/Images/Products/" + item.ProductImage, new { width = "65px", height = "100px", alt = "some alt text" })
                    <div class="hover_shine">
                    </div>
                </div>
            </td>
            <td>
                @Html.ActionLink("Edit", "EditProduct", new { id = item.ProductId })
                <a href="#" class="RemoveProduct" data-id="@item.ProductId" data-name="@item.ProductName">Delete</a>
            </td>
        </tr>
        
    }
    <tr>
        <td colspan="7" align="right">
            @Html.ActionLink("Create Product", "CreateProduct")
        </td>
    </tr>
</table>
<!--Paging-->
@Html.PagedListPager(Model, page => Url.Action("ShowProduct", new { page = page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }), (PagedListRenderOptions)ViewBag.Pro)
